Table of Contents

In [39]:
import numpy as np
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
In [40]:
!display?
In [ ]:
!display
In [41]:
!display
'display' is not recognized as an internal or external command,
operable program or batch file.
In [42]:
from bokeh.io import output_notebook, output_file
from bokeh.plotting import show, figure 
from bokeh.layouts import gridplot, column
from bokeh.models import HoverTool, ColumnDataSource, Jitter, Label, Span, LinearInterpolator, CategoricalColorMapper
from bokeh.models.widgets import Panel, Tabs, Div
from datetime import datetime as dt
import time
import numpy as np
import pandas as pd
from pandas.io import gbq
projectId = 'mindful-carport-156107'
output_notebook()
h = 400

w = 1200
bbSmall = 5
bbBig = 50
legendCat1 = '6pt'
legendCity = '6pt'
legendSource = '8pt'
startDate = '2017-03-01'
tvcDate1 = time.mktime(dt(2017, 5, 12, 2, 0, 0).timetuple())*1000

tvcDate = time.mktime(dt(2017, 9, 21, 2, 0, 0).timetuple())*1000
tvcDate2 = time.mktime(dt(2017, 11, 13, 2, 0, 0).timetuple())*1000

eurekaDate = time.mktime(dt(2017, 10, 6, 2, 0, 0).timetuple())*1000
hash = {}
c = ('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 
    'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 
    'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 
    'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 
    'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 
    'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 
    'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 
    'gray', 'green', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 
    'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 
    'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 
    'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 
    'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 
    'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 
    'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 
    'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 
    'purple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 
    'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 
    'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen');

# Holoviews plot
import holoviews as hv
from pandas.io import gbq
hv.extension('bokeh')

h = 600
w = 1500

from plotly import tools
import plotly.graph_objs as go
import plotly as py
from plotly.graph_objs import Scatter, Layout
py.offline.init_notebook_mode()
import cufflinks as cf
cf.set_config_file(offline=True, world_readable=False, theme='pearl')
import plotly.figure_factory as ff
Loading BokehJS ...

Analyze

In [43]:
#Importing the libraries
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt # basic plotting
import seaborn as sns # more plotting

#Importing the data
events = pd.read_csv('./football-events/events.csv')
ginf = pd.read_csv('./football-events/ginf.csv')
In [44]:
display( ginf.head(10))
ginf.info()
id_odsp link_odsp adv_stats date league season country ht at fthg ftag odd_h odd_d odd_a odd_over odd_under odd_bts odd_bts_n
0 UFot0hit/ /soccer/germany/bundesliga-2011-2012/dortmund-... True 2011-08-05 D1 2012 germany Borussia Dortmund Hamburg SV 3 1 1.56 4.41 7.42 NaN NaN NaN NaN
1 Aw5DflLH/ /soccer/germany/bundesliga-2011-2012/augsburg-... True 2011-08-06 D1 2012 germany FC Augsburg SC Freiburg 2 2 2.36 3.60 3.40 NaN NaN NaN NaN
2 bkjpaC6n/ /soccer/germany/bundesliga-2011-2012/werder-br... True 2011-08-06 D1 2012 germany Werder Bremen Kaiserslautern 2 0 1.83 4.20 4.80 NaN NaN NaN NaN
3 CzPV312a/ /soccer/france/ligue-1-2011-2012/paris-sg-lori... True 2011-08-06 F1 2012 france Paris Saint-Germain Lorient 0 1 1.55 4.50 9.40 NaN NaN NaN NaN
4 GUOdmtII/ /soccer/france/ligue-1-2011-2012/caen-valencie... True 2011-08-06 F1 2012 france Caen Valenciennes 1 0 2.50 3.40 3.45 NaN NaN NaN NaN
5 lOpzwMkp/ /soccer/germany/bundesliga-2011-2012/hertha-be... True 2011-08-06 D1 2012 germany Hertha Berlin Nurnberg 0 1 2.06 3.75 3.95 NaN NaN NaN NaN
6 M7PhlM2C/ /soccer/france/ligue-1-2011-2012/brest-evian-t... True 2011-08-06 F1 2012 france Brest Evian Thonon Gaillard 2 2 2.29 3.25 3.85 NaN NaN NaN NaN
7 QuWqjrYa/ /soccer/france/ligue-1-2011-2012/ac-ajaccio-to... True 2011-08-06 F1 2012 france AC Ajaccio Toulouse 0 2 2.80 3.10 3.05 NaN NaN NaN NaN
8 UBZQ4smg/ /soccer/france/ligue-1-2011-2012/nice-lyon-UBZ... True 2011-08-06 F1 2012 france Nice Lyon 1 3 4.50 3.55 2.00 NaN NaN NaN NaN
9 Wn69eU5B/ /soccer/germany/bundesliga-2011-2012/koln-wolf... True 2011-08-06 D1 2012 germany FC Cologne VfL Wolfsburg 0 3 3.00 3.80 2.54 NaN NaN NaN NaN
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10112 entries, 0 to 10111
Data columns (total 18 columns):
id_odsp      10112 non-null object
link_odsp    10112 non-null object
adv_stats    10112 non-null bool
date         10112 non-null object
league       10112 non-null object
season       10112 non-null int64
country      10112 non-null object
ht           10112 non-null object
at           10112 non-null object
fthg         10112 non-null int64
ftag         10112 non-null int64
odd_h        10112 non-null float64
odd_d        10112 non-null float64
odd_a        10112 non-null float64
odd_over     977 non-null float64
odd_under    977 non-null float64
odd_bts      977 non-null float64
odd_bts_n    977 non-null float64
dtypes: bool(1), float64(7), int64(3), object(7)
memory usage: 1.3+ MB
In [45]:
# display( events.head())
# events.info()
# display(events[['event_team','opponent']].describe())
# events[['event_team','opponent']].iplot(kind='histogram', subplots=True)
In [46]:
# df = ginf.copy().groupby(['date','country']).agg(['count']).reset_index()
df = ginf.copy().groupby(['date','country']).size().reset_index(name='counts')
df = pd.pivot_table(df,  index=['date'], columns=['country'], values='counts', aggfunc=np.sum)
df = df.fillna(0)
df.dtypes
# df.date = pd.to_datetime(df.date)
df.index = pd.to_datetime(df.index)
df['total'] = df['england']+df['france']+df['germany']+df['italy']+df['spain']
df.resample('W').sum().iplot(kind='scatter', subplots=True, shape=(6,1), shared_xaxes=True,  subplot_titles=True)
In [47]:
!jupyter nbconvert --to html --CodeFoldingPreprocessor.remove_folded_code=True football.ipynb
from shutil import copy2
copy2('football.html','C:/Users/Khanh/Google Drive/Github/khanhdinh.github.io/_posts/2017-12-09-football.html')
[NbConvertApp] Converting notebook football.ipynb to html
[NbConvertApp] Writing 8413139 bytes to football.html
Out[47]:
'C:/Users/Khanh/Google Drive/Github/khanhdinh.github.io/_posts/2017-12-09-football.html'
In [48]:
!nbconvert?
Object `nbconvert` not found.
In [49]:
!jupyter --path
config:
    C:\Users\Khanh\.jupyter
    c:\program files\python35\etc\jupyter
    C:\ProgramData\jupyter
data:
    C:\Users\Khanh\AppData\Roaming\jupyter
    c:\program files\python35\share\jupyter
    C:\ProgramData\jupyter
runtime:
    C:\Users\Khanh\AppData\Roaming\jupyter\runtime